package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.entity.Employee;
import com.itheima.service.EmployeeService;
import com.itheima.mapper.EmployeeMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
* @author liukailei
* @description 针对表【employee(员工信息)】的数据库操作Service实现
* @createDate 2024-11-10 20:14:59
*/
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee>
    implements EmployeeService{

    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public IPage<Employee> selectPage(String name, int page, int pageSize) {
        IPage<Employee> page1 = new Page<>(page, pageSize);
        LambdaQueryWrapper<Employee> queryWrapper  = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(name), Employee::getName, name)
                .orderByDesc(Employee::getUpdateTime);
        employeeMapper.selectPage(page1, queryWrapper);
        return page1;
    }

    @Override
    public void updateEmploy(Employee employee) {
        employeeMapper.updateById(employee);
    }

    @Override
    public Employee selectById(Long id) {
        Employee employee = employeeMapper.selectById(id);
        return employee;
    }
}




